package com.fgr;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;

import java.sql.Types;
import java.util.Collections;
//mybatis-plus代码生成器
public class Generater {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql:///animaldb?userUnicode=true&characterEncoding=utf-8&useSSL=false", "root", "ykh31800")
                .globalConfig(builder -> {
                    builder.author("xiaokai") // 设置作者
                            .outputDir("D:\\学习资料\\大三下\\小组项目\\前端静态资源\\HelpAnimal\\src\\main\\java"); // 指定输出目录
                })
                .dataSourceConfig(builder -> builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
                    int typeCode = metaInfo.getJdbcType().TYPE_CODE;
                    if (typeCode == Types.SMALLINT) {
                        // 自定义类型转换
                        return DbColumnType.INTEGER;
                    }
                    return typeRegistry.getColumnType(metaInfo);

                }))
                .packageConfig(builder -> {
                    builder.parent("com") // 设置父包名
                            .moduleName("fgr") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "D:\\学习资料\\大三下\\小组项目\\前端静态资源\\HelpAnimal\\src\\main\\resources\\com\\fgr\\mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("an_animal","an_adapter","an_user","an_donation","an_donationtype","an_help","an_message","an_messagetype","an_animaltype") // 设置需要生成的表名
                            .addTablePrefix("an_"); // 设置过滤表前缀
                })
                .execute();
    }
}
